<?php

/**
 * Class TaxonomyUpdateAction
 */
class TaxonomyUpdateAction extends CAction
{
	public $view = 'update';

	public $bundle;

	public function run($id)
	{
		$model = $this->loadModel($id);

		if (isset($_POST['Taxonomy'])) {
			$model->attributes = $_POST['Taxonomy'];

			if ($model->save()) {
				Yii::app()->getUser()->setFlash('success', '分类更新成功');
				if (isset($_POST['_addanother'])) {
					$url = array('create');
				} elseif (isset($_POST['_continue'])) {
					$url = array('update', 'id' => $model->id);
				} else {
					$url = array('view', 'id' => $model->id);
				}
				$this->getController()->redirect($url);
			}
		}

		$this->getController()->render($this->view, array('model' => $model));

	}

	public function loadModel($id)
	{
		if ($this->bundle) {
			$condition = 'bundle=:bundle';
			$params = array(':bundle' => $this->bundle);
		} else {
			$condition = '';
			$params = array();
		}
		if (!$model = Taxonomy::model()->findByPk($id, $condition, $params)) {
			throw new CHttpException(404, '页面没有找到');
		}
		return $model;
	}
} 